home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Unix / Utilities / ListFonts / Source / ListFonts.c
Encoding:
C/C++ Source or Header  |  1992-01-16  |  2.0 KB  |  74 lines

  1. /*
  2.  *    ListFonts - lists fonts on NeXT's
  3.  *    (c) by gfa  <george@nice.usergroup.ethz.ch>
  4.  *    Sat Jan 11 23:37:32 GMT+0100 1992
  5.  */
  6.  
  7. #include <sys/types.h>
  8. #import <sys/dir.h>
  9. #include <stdio.h>
  10. #include <syslog.h>
  11. #include <strings.h>
  12.  
  13. #define SIZE 18
  14. #define PAGECLIP  0, 0, 530, 840
  15. #define NUM_PATHS 2
  16. #define PAPER_LENGTH 600
  17.  
  18. main(int argc, char **argv) {
  19.     
  20.     struct direct  *dp;
  21.     DIR *dirp;
  22.     int  a, b, n, i, k, j;
  23.     char  fontarray[2000][127], fontname[127], 
  24.     pathname[NUM_PATHS][1024] = { "/LocalLibrary/Fonts", "/NextLibrary/Fonts"};
  25.     
  26.     openlog("FontLister", LOG_PID, LOG_DAEMON);
  27.  
  28.     a = 0;
  29.     for (b = 0; b < NUM_PATHS; b++) {
  30.         dirp = opendir(pathname[b]);
  31.         if (dirp == NULL) {
  32.             syslog(LOG_ERR, "cannot open %s", pathname[b]);
  33.             exit(1);
  34.         }
  35.         for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
  36.             i = 0;
  37.             while (dp->d_name[i] != '.' &&  dp->d_name[i] != '\0') {
  38.                 fontname[i] = dp->d_name[i];
  39.                 ++i;
  40.             }
  41.             fontname[i] = '\0';
  42.             if (dp->d_name[i] == '.' && dp->d_name[i + 1] == 'f' && dp->d_name[i + 2] == 'o' &&
  43.             dp->d_name[i + 3] == 'n' && dp->d_name[i + 4] == 't' && dp->d_name[i + 5] == '\0') {
  44.                 strcpy(fontarray[a], fontname);
  45.                 ++a;
  46.             }
  47.         }    
  48.     }
  49.     qsort(&fontarray[0][0], a, 127, strcmp);
  50.  
  51.     printf("%%!PS-Adobe-2.0\n%%%%DocumentPaperSizes: A4\n");
  52.     printf("%%%%Pages: (atend) 1\n%%EndComments\n");
  53.     printf("%%%%Page: 1 1\n %d %d %d %d rectclip\n", PAGECLIP);
  54.  
  55.     j = 0; k = 2;
  56.     for (n = 0; n < a; ++n) {
  57.         printf("%d %d moveto\n", 3*SIZE, 760 - j*(SIZE + 4));
  58.         printf("/Helvetica findfont %d scalefont setfont\n", SIZE/2);
  59.         printf("(%d. %s) show\n", n+1, fontarray[n]);
  60.         printf("%d %d moveto\n", 11*SIZE, 760 - j*(SIZE + 4));
  61.         printf("/%s findfont %d scalefont setfont\n", fontarray[n], SIZE-4);
  62.         printf("(The Quick Brown Fox Jumps Over The Lazy Dog) show\n");
  63.         ++j;
  64.         if (j == (PAPER_LENGTH/SIZE)) {
  65.             j = 0;
  66.             printf("showpage\n");
  67.             printf("%%%%Page: %d %d\n %d %d %d %d rectclip\n", k, k, PAGECLIP);
  68.             ++k;
  69.         }
  70.     }
  71.     printf("showpage\n");
  72.     printf("%%%%Trailer\n%%%%Pages: %d %d\n", k-1, 1);
  73. }    
  74.